import 'package:flutter/material.dart';
import 'package:qgchat/bloc/shortvideo/popularvideoBloc.dart';
import 'package:qgchat/common/global/global.dart';
import 'package:qgchat/page/video/hot/index.dart';
import 'package:qgchat/page/video/focus/index.dart';
import 'package:qgchat/page/video/newest/index.dart';

class VideoBar extends StatefulWidget {
  @override
  _VideoBarState createState() => _VideoBarState();
}

class _VideoBarState extends State<VideoBar> with TickerProviderStateMixin {
  // tabbar顶部
  final tabs = ["关注", "热门", "最新"];

  // bloc
  PopularBloc popluar = PopularBloc();

  TabController tabC;

  @override
  void initState() {
    super.initState();
    tabC = TabController(
      initialIndex: 1,
      vsync: this,
      length: tabs.length,
    );
  }

  //  顶部tabbar
  Widget getTabBar() {
    return TabBar(
      controller: tabC,
      isScrollable: true,
      labelColor: col("303133"),
      labelPadding: EdgeInsets.symmetric(horizontal: px(34)),
      labelStyle: TextStyle(
        fontWeight: FontWeight.bold,
      ),
      unselectedLabelStyle: TextStyle(fontSize: px(34)),
      unselectedLabelColor: col("303133"),
      indicatorColor: col("d35edd"),
      indicatorSize: TabBarIndicatorSize.label,
      indicatorWeight: px(6),
      tabs: tabs.map((t) {
        return Tab(
          child: Text(t),
        );
      }).toList(),
    );
  }

// 生成tabview
  Widget getTabBarPages() {
    return TabBarView(
      controller: tabC,
      children: <Widget>[
        Focuse(),
        Hot(),
        Newest(),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: tabs.length,
      child: Scaffold(
        appBar: AppBar(
          flexibleSpace: SafeArea(
            child: Column(
              children: <Widget>[
                getTabBar(),
              ],
            ),
          ),
        ),
        body: getTabBarPages(),
      ),
    );
  }
}
